home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / bash_114.zip / bash-1.14.2 / general.h < prev    next >
C/C++ Source or Header  |  1994-07-14  |  7KB  |  228 lines

  1. /* general.h -- defines that everybody likes to use. */
  2.  
  3. /* Copyright (C) 1993 Free Software Foundation, Inc.
  4.  
  5.    This file is part of GNU Bash, the Bourne Again SHell.
  6.  
  7.    Bash is free software; you can redistribute it and/or modify it under
  8.    the terms of the GNU General Public License as published by the Free
  9.    Software Foundation; either version 2, or (at your option) any later
  10.    version.
  11.  
  12.    Bash is distributed in the hope that it will be useful, but WITHOUT ANY
  13.    WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14.    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15.    for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License along
  18.    with Bash; see the file COPYING.  If not, write to the Free Software
  19.    Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  20.  
  21. #if !defined (_GENERAL_H)
  22. #define _GENERAL_H
  23.  
  24. #include "stdc.h"
  25.  
  26. #if !defined (NULL)
  27. #  if defined (__STDC__)
  28. #    define NULL ((void *) 0)
  29. #  else
  30. #    define NULL 0x0
  31. #  endif /* !__STDC__ */
  32. #endif /* !NULL */
  33.  
  34. #if defined (HAVE_STRING_H)
  35. #  include <string.h>
  36. #else
  37. #  include <strings.h>
  38. #endif /* !HAVE_STRING_H */
  39.  
  40. #define pointer_to_int(x) (int)((long)(x))
  41.  
  42. #if !defined (savestring)
  43.    extern char *xmalloc ();
  44. #  if !defined (strcpy)
  45.    extern char *strcpy ();
  46. #  endif
  47. #  define savestring(x) (char *)strcpy (xmalloc (1 + strlen (x)), (x))
  48. #endif
  49.  
  50. #ifndef whitespace
  51. #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
  52. #endif
  53.  
  54. #ifndef digit
  55. #define digit(c)  ((c) >= '0' && (c) <= '9')
  56. #endif
  57.  
  58. #ifndef isletter
  59. #define isletter(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
  60. #endif
  61.  
  62. #ifndef digit_value
  63. #define digit_value(c) ((c) - '0')
  64. #endif
  65.  
  66. #if !defined (__STDC__) && !defined (strchr)
  67. extern char *strchr (), *strrchr ();
  68. #endif /* !strchr */
  69.  
  70. #ifndef member
  71. #  if defined (alpha) && defined (__GNUC__)    /* XXX */
  72.      extern char *strchr ();
  73. #  endif
  74. #  define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0)
  75. #endif
  76.  
  77. /* All structs which contain a `next' field should have that field
  78.    as the first field in the struct.  This means that functions
  79.    can be written to handle the general case for linked lists. */
  80. typedef struct g_list {
  81.   struct g_list *next;
  82. } GENERIC_LIST;
  83.  
  84. /* Here is a generic structure for associating character strings
  85.    with integers.  It is used in the parser for shell tokenization. */
  86. typedef struct {
  87.   char *word;
  88.   int token;
  89. } STRING_INT_ALIST;
  90.  
  91. /* A macro to avoid making an uneccessary function call. */
  92. #define REVERSE_LIST(list, type) \
  93.   ((list && list->next) ? (type)reverse_list ((GENERIC_LIST *)list) : (type)(list))
  94.  
  95. #if __GNUC__ > 1
  96. #  define FASTCOPY(s, d, n)  __builtin_memcpy (d, s, n)
  97. #else /* !__GNUC__ */
  98. #  if defined (USG) && !defined (HAVE_BCOPY)
  99. #    if defined (MEMMOVE_MISSING)
  100. #      define FASTCOPY(s, d, n)  memcpy (d, s, n)
  101. #    else
  102. #      define FASTCOPY(s, d, n)  memmove (d, s, n)
  103. #    endif /* !MEMMOVE_MISSING */
  104. #  else
  105. #    define FASTCOPY(s, d, n)  bcopy (s, d, n)
  106. #  endif /* !USG || HAVE_BCOPY */
  107. #endif /* !__GNUC__ */
  108.  
  109. /* String comparisons that possibly save a function call each. */
  110. #define STREQ(a, b) ((a)[0] == (b)[0] && strcmp(a, b) == 0)
  111. #define STREQN(a, b, n) ((a)[0] == (b)[0] && strncmp(a, b, n) == 0)
  112.  
  113. /* More convenience definitions that possibly save system or libc calls. */
  114. #define STRLEN(s) ((s)[0] ? ((s)[1] ? ((s)[2] ? strlen(s) : 2) : 1) : 0)
  115. #define FREE(s)  do { if (s) free (s); } while (0)
  116. #define MEMBER(c, s) (((c) && !(s)[1] && c == s[0]) || (member(c, s)))
  117.  
  118. /* What type is a `generic' pointer?  This is used as the first argument
  119.    to xrealloc. */
  120. #if defined (__STDC__)
  121. typedef void *GENPTR;
  122. #else
  123. typedef char *GENPTR;
  124. #endif
  125.  
  126. /* Function pointers can be declared as (Function *)foo. */
  127. #if !defined (__FUNCTION_DEF)
  128. #  define __FUNCTION_DEF
  129. typedef int Function ();
  130. typedef void VFunction ();
  131. typedef char *CPFunction ();
  132. typedef char **CPPFunction ();
  133. #endif /* _FUNCTION_DEF */
  134.  
  135. #define NOW    ((time_t) time ((time_t *) 0))
  136.  
  137. /* Some defines for calling file status functions. */
  138. #define FS_EXISTS      0x1
  139. #define FS_EXECABLE      0x2
  140. #define FS_EXEC_PREFERRED 0x4
  141. #define FS_EXEC_ONLY      0x8
  142.  
  143. /* Posix and USG systems do not guarantee to restart a read () that is
  144.    interrupted by a signal. */
  145. #if defined (USG) || defined (_POSIX_VERSION)
  146. #  define NO_READ_RESTART_ON_SIGNAL
  147. #endif /* USG || _POSIX_VERSION */
  148.  
  149. /* Here is a definition for set_signal_handler () which simply expands to
  150.    a call to signal () for non-Posix systems.  The code for set_signal_handler
  151.    in the Posix case resides in general.c. */
  152.  
  153. #if defined (VOID_SIGHANDLER)
  154. #  define sighandler void
  155. #else
  156. #  define sighandler int
  157. #endif /* !VOID_SIGHANDLER */
  158.  
  159. typedef sighandler SigHandler ();
  160.  
  161. #if !defined (_POSIX_VERSION)
  162. #  define set_signal_handler(sig, handler) (SigHandler *)signal (sig, handler)
  163. #else
  164. extern SigHandler *set_signal_handler ();
  165. #endif /* _POSIX_VERSION */
  166.  
  167. /* This function is defined in trap.c. */
  168. extern SigHandler *set_sigint_handler __P((void));
  169.  
  170. /* Declarations for functions defined in general.c */
  171. extern char *xmalloc __P((int));
  172. extern char *xrealloc __P((void *, int));
  173. extern void xfree __P((char *));
  174. extern char *itos __P((int));
  175. extern int all_digits __P((char *));
  176. extern long string_to_long __P((char *));
  177. extern int legal_identifier __P((char *));
  178. extern int check_identifier __P((WORD_DESC *, int));
  179. extern void unset_nodelay_mode __P((int));
  180. extern void map_over_words __P((WORD_LIST *, Function *));
  181.  
  182. extern void map_over_list __P((GENERIC_LIST *, Function *));
  183. extern GENERIC_LIST *reverse_list ();
  184. extern GENERIC_LIST *delete_element ();
  185. extern GENERIC_LIST *list_append ();
  186. extern int list_length ();
  187. extern int qsort_string_compare ();
  188.  
  189. extern int find_name_in_list __P((char *, char **));
  190. extern int array_len __P((char **));
  191. extern void free_array __P((char **));
  192. extern char **copy_array __P((char **));
  193. extern void strip_leading __P((char *));
  194. extern void strip_trailing __P((char *, int));
  195. extern char *canonicalize_pathname __P((char *));
  196. extern char *make_absolute __P((char *, char *));
  197. extern int absolute_pathname __P((char *));
  198. extern int absolute_program __P((char *));
  199. extern char *base_pathname __P((char *));
  200. extern char *full_pathname __P((char *));
  201. extern char *strindex __P((char *, char *));
  202. extern void set_lines_and_columns __P((int, int));
  203. extern void xbcopy __P((char *, char *, int));
  204. extern char *polite_directory_format __P((char *));
  205. extern void tilde_initialize __P((void));
  206.  
  207. #if !defined (strerror)
  208. extern char *strerror __P((int));
  209. #endif
  210.  
  211. #if !defined (HAVE_STRCASECMP)
  212. extern int strnicmp __P((char *, char *, int));
  213. extern int stricmp __P((char *, char *));
  214. #else /* HAVE_STRCASECMP */
  215. #  define stricmp strcasecmp
  216. #  define strnicmp strncasecmp
  217. #endif /* HAVE_STRCASECMP */
  218.  
  219. extern int dup2 __P((int, int));
  220. extern char *getwd __P((char *));
  221. extern int getdtablesize __P((void));
  222.  
  223. #if defined (USG) && !defined (HAVE_GETHOSTNAME)
  224. extern int gethostname __P((char *, int));
  225. #endif /* USG && !HAVE_GETHOSTNAME */
  226.  
  227. #endif    /* _GENERAL_H */
  228.